package com.peoit.honeycomb.rest;

import com.peoit.honeycomb.application.BannerApplication;
import com.peoit.honeycomb.dto.BannerDto;
import com.peoit.honeycomb.dto.CommonResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * banner管理
 * Created by zhouqiu on 2015/10/26.
 */
@Controller
@RequestMapping("/api/banner")
public class BannerResource extends  BaseResource {

    @Autowired
    BannerApplication bannerApplication;

    @RequestMapping(value = "/getBannerList" , method = RequestMethod.POST)
    public @ResponseBody CommonResultDto getBannerList(String city){
        CommonResultDto result = new CommonResultDto();
        List<BannerDto> all = null;
        try {
            all = this.bannerApplication.findAllBy(city);
        }catch (Exception ex) {
            ex.printStackTrace();
            result.setReason("internal error: " + ex.getMessage());
            result.setResult_code("500");
        }
        if(all == null || all.size()<=0){
            result.setReason("not data");
            result.setResult_code("400");
        }else {
            result.setResult(all);
            result.setReason("success");
            result.setResult_code("200");
        }
        return result;
    }

}
